import axios from 'axios'
import { assert } from '@/utils/assert'



// 创建一个定制化的axios实例
const request = axios.create({
    timeout: 5000, // 超时时间
    headers: {
        "Content-Type": "application/json"
    }
})

// 添加响应拦截器
request.interceptors.response.use(
    response => {
        const retCode = response.data.ret_code
        // console.log(`响应结果: ${JSON.stringify(response.data)}`)
        assert(retCode == '00', "响应异常")
        return response.data.data
    },
    error => {
        console.log(`http响应异常: ${JSON.stringify(error)}`)
        return Promise.reject(error)
    }
)

export default request